package com.cicc.beergamevirtualsimulationsystem.controller;

import com.cicc.beergamevirtualsimulationsystem.model.R;
import com.cicc.beergamevirtualsimulationsystem.model.roleBinding.RoleBindingReq;
import com.cicc.beergamevirtualsimulationsystem.model.room.dto.CreateRoomDto;
import com.cicc.beergamevirtualsimulationsystem.model.room.dto.QueryJoinRoomDto;
import com.cicc.beergamevirtualsimulationsystem.model.room.dto.QueryRoomDto;
import com.cicc.beergamevirtualsimulationsystem.model.room.dto.QueryRoomRecordDto;
import com.cicc.beergamevirtualsimulationsystem.model.room.req.CreateRoomReq;
import com.cicc.beergamevirtualsimulationsystem.service.RoomService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房间
 *
 * @author 银角大王
 */
@RequestMapping("/api/room")
@RestController
@RequiredArgsConstructor
public class RoomController {

    private final RoomService roomService;

    /**
     * 根据口令查询房间
     *
     * @return
     */
    @GetMapping("/{command}")
    public R<QueryRoomDto> queryRoomByCommand(@PathVariable String command) {
        return R.ok(roomService.queryRoomByCommand(command));
    }

    /**
     * 创建房间
     */
    @PostMapping
    public R<CreateRoomDto> createRoom(@Valid @RequestBody CreateRoomReq createRoomReq) {
        return R.ok(roomService.createRoom(createRoomReq));
    }


    /**
     * 查询是否存在已经参与的游戏
     */
    @GetMapping
    public R<QueryJoinRoomDto> queryGame() {
        return R.ok(roomService.queryGame());
    }
    /**
     * 用户游戏历史记录
     */
    @GetMapping("/queryRoomRecord")
    public R<List<QueryRoomRecordDto>> queryRoomRecord() {
        return R.ok(roomService.queryRoomRecord());
    }

    /**
     * 查看房间状态
     */
    @GetMapping("/status/{roomId}")
    public R<Integer> queryRoomStatus(@PathVariable String roomId) {
        return R.ok(roomService.queryRoomStatus(roomId));
    }

    /**
     * 再来一把
     */
    @GetMapping("/playAgain/{roomId}")
    public R<CreateRoomDto> playAgain(@PathVariable String roomId) {
        return R.ok(roomService.playAgain(roomId));
    }

}
